<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="e.name">
  <input type="text" placeholder="请输入员工工资" v-model="e.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="e.title">
  <br>
  <button @click="add()">点击添加</button>
  <hr>
  <table border="1px">
    <caption>员工表</caption>
    <tr>
      <th>员工编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(emp,index) in emps">
      <td>{{ index + 1 }}</td>
      <td>{{emp.name}}</td>
      <td>{{emp.salary}}</td>
      <td>{{emp.title}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const emps = ref([]);
const e = ref({name:'',salary:'',title:''})
const add = () => {
  if (e.value.name.trim()==''||e.value.salary.trim()==''||e.value.title.trim()=='') {
    alert('请输入完整信息');
    return;
  }
  emps.value.push(e.value);
  e.value = {name:'',salary:'',title:''};
}
</script>

<style scoped>

</style>